import urllib.request
import io
import sys

# 想在不关闭一个已打开的文件前提下增加或改变它的Unicode编码
def demo_1():
    u = urllib.request.urlopen('http://www.python.org')
    f = io.TextIOWrapper(u, encoding='utf-8')
    text = f.read()
    print(text)

# 更改编码
def demo_2():
    print(sys.stdout.encoding)
    sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding='latin-1')
    print(sys.stdout.encoding)

if __name__ == '__main__':
    demo_1()
    # demo_2()